package it.uniroma2.art.owlart.langsearch.analysis;

import java.io.Reader;

import org.apache.lucene.analysis.ASCIIFoldingFilter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
import org.apache.lucene.analysis.KeywordTokenizer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.Version;

/**
 * a filter which makes the analysis:
 * <ul>
 * <li>insensitive to diacritics, by using {@link ASCIIFoldingFilter}</li>
 * <li>insensitive to case, by using {@link LowerCaseFilter}</li>
 * </ul>
 * 
 * @author Armando Stellato <a href="mailto:stellato@info.uniroma2.it">stellato@info.uniroma2.it</a>
 *
 */
public class StarredGenericNonTokenizingAnalyzer extends Analyzer {

	public TokenStream tokenStream(String fieldName, Reader reader) {
		TokenStream result = 
				// TODO ISOLatin1AccentFilter to be used in old version of Lucene
				new ASCIIFoldingFilter (
						new LowerCaseFilter(Version.LUCENE_36, 
								new StandardFilter(Version.LUCENE_36,										
										// new StandardTokenizer(Version.LUCENE_36, reader)
										new KeywordTokenizer(reader)
								)
				)		
		);
		return result;
	}
}
